using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;
using System.Xml.XPath;
using System.IO;

namespace Ricciolo.StylesExplorer.Model
{
    /// <summary>
    /// Rappresenta un'eccezione di decompilazione Baml
    /// </summary>
    [Serializable()]
    class DecompilingXamlException : Exception
    {

        private byte[] _bamlData;
        private Exception _innerException;

        public DecompilingXamlException(string message) : base(message)
        {
        }

        public DecompilingXamlException(string message, Exception innerException)
            : base(message)
        {
            this._innerException = innerException;
        }

        // Don't call inner exception because I loose main exception
        public DecompilingXamlException(string message, byte[] bamlData, Exception innerException)
            : base(message)
        {
            this._innerException = innerException;
            this._bamlData = bamlData;
        }

        public DecompilingXamlException(SerializationInfo info, StreamingContext context) : base(info, context)
        {
        }

        public DecompilingXamlException()
        {
        }

        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            base.GetObjectData(info, context);

            info.AddValue("bamlData", this.BamlData, typeof(byte[]));
        }

        public override string ToString()
        {
            if (_innerException != null)
                return base.ToString() + "\r\n---Inner---" + _innerException.ToString();
            else
                return base.ToString();
        }

        public byte[] BamlData
        {
            get { return _bamlData; }
        }
    }
}
